package com.wanggy.mystore.service.impl;

import com.wanggy.mystore.entity.District;
import com.wanggy.mystore.mapper.DistrictMapper;
import com.wanggy.mystore.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DistrictServiceImpl implements IDistrictService {
    @Autowired
    private DistrictMapper districtMapper;
    @Override
    public List<District> getByParent(String parent) {
        List<District> resultList = districtMapper.findByParent(parent);
        /**
         * 在进行网络数据传输市，为了尽量避免无效数据的传递，可以将
         * 无效数据设置为null，这样既节省流量，又提升了效率
         */
        for(District district : resultList){
            district.setId(null);
            district.setParent(null);
        }

        return resultList;
    }


    /***
     * 根据代码获取省市区的名称
     * @param code 代码
     * @return 名称
     */
    @Override
    public String findNameByCode(String code) {
        return districtMapper.findNameByCode(code);
    }
}
